package org.fuys.coder.common.util;

import de.mkammerer.argon2.Argon2;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.common.util
 * @className: EncryptUtil
 * @author: WangJing
 * @description: 密码加密工具类
 * @date: 2024/6/19 16:56
 * @version: 1.0
 */
@Service
public class EncryptUtil {
    @Resource
    private Argon2 argon2;
    private static final String SALT = "fuys";
    public String encodePassword(String pwd){
        final byte[] bytes = SALT.getBytes(StandardCharsets.UTF_8);
        return argon2.hash(1, 65536, 1, pwd.getBytes(StandardCharsets.UTF_8));
    }

    //第二个参数是数据库存储的 第一个参数是原始密码
    public boolean verifyPassword(String pwd,String hash){
        return argon2.verify(hash,pwd.getBytes(StandardCharsets.UTF_8));
    }

}
